.data
output_format:
    .asciz "%d\n"
input_format:
    .asciz "%d"
input_prompt:
    .asciz "请输入一个数:"
n:
    .word 0  @ 定义一个名为n的整数变量，初始化为0

.text
.global main

main:
    @ 保存寄存器
    push {r4, r5, r6, r7, lr}

    @ 输出提示
    ldr r0, =input_prompt
    bl printf

    @ 输入n
    ldr r0, =input_format
    ldr r1, =n
    bl scanf

    @ 初始化变量
    mov r4, #0   @ a = 0
    mov r5, #1   @ b = 1
    mov r6, #0   @ i = 0

    loop_start:
        @ 输出当前Fibonacci数
        ldr r0, =output_format
        mov r1, r4
        bl printf

        @ 计算下一个Fibonacci数
        add r7, r4, r5  @ t = a + b
        mov r4, r5       @ a = b
        mov r5, r7       @ b = t

        @ 更新循环变量i
        add r6, r6, #1

        @ 检查是否需要继续循环
        ldr r0, =n
        ldr r1, [r0]
        cmp r6, r1
        blt loop_start

    @ 恢复寄存器并退出程序
    pop {r4, r5, r6, r7, lr}
    mov r0, #0
    bx lr
